﻿using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System;
using BE;


namespace DAL
{
	public class SqlCommands
	{
		internal SqlConnection GetConnection()
		{
			string constring="";
			try
			{
				using ( StreamReader reader = new StreamReader( @"C:\weboptions\dbconfig.txt" ) )
				{
					
					string line; while ( ( line = reader.ReadLine() ) != null )
					{
						constring = line.Split('=')[1];
					}
				}
				if ( constring.Length == 0 )
					constring = ".\\sqlexpress";
			}
			catch
			{
				constring = ".\\sqlexpress";
			}
			string ConnectionString = "Data Source="+constring+";Initial Catalog=Bellevue;Integrated Security=True;";
			return new SqlConnection( ConnectionString );
		}

		public bool testconnection()
		{
			SqlConnection con = GetConnection();
			try
			{
				con.Open();
				
			}
			catch(Exception e)
			{
				EasyException es = new EasyException( "ConnectionString:\n" + con.ConnectionString, e );
				throw es;	
			}

			return true;
		}

		
	}
}
